<?php
#
# Author: Cody Sorgenfrey and Phil Spagnolo
#

include_once("common.php");

include_once("../common.php");

$title= "Mobile";
$meta_key= "Church, Puyallup, SHCC, South Hill, Calvary Chapel, South Hill Calvary Chapel";
$meta_desc= "The mobile site for Puyallup church; South Hill Calvary Chapel";
$morehtml= "<link rel='stylesheet' type='text/css' href='js/galleryview/css/jquery.galleryview-3.0-dev.css'/>\n";

if (userIsTab()){	
	$slideIn = "<script type='text/javascript'>
	window.addEventListener('load',slideIn, false);
	function slideIn(){
		document.getElementById('sermons').style.webkitTransform = 'translateX(0%)';
			document.getElementById('sermons').style.MozTransform = 'translateX(0%)';
			document.getElementById('sermons').style.OTransform = 'translateX(0%)';
		setTimeout(function(){
			document.getElementById('stayConnectedBlock').style.webkitTransform = 'translateX(0%)';
				document.getElementById('stayConnectedBlock').style.MozTransform = 'translateX(0%)';
				document.getElementById('stayConnectedBlock').style.OTransform = 'translateX(0%)';
		}, 200); 
	}
</script>";
}
else{	
	$slideIn = "<script type='text/javascript'>
	window.addEventListener('load', slideIn, false);
	function slideIn(){
		document.getElementById('sermons').style.webkitTransform = 'translateX(0%)';
			document.getElementById('sermons').style.MozTransform = 'translateX(0%)';
			document.getElementById('sermons').style.OTransform = 'translateX(0%)';
		document.getElementById('plainlist').style.webkitTransform = 'rotateZ(0deg)';
			document.getElementById('plainlist').style.MozTransform = 'rotateZ(0deg)';
			document.getElementById('plainlist').style.OTransform = 'rotateZ(0deg)';
		hideSafariBar();
	}
	</script>";	
}
$morejava= "
	<script type='text/javascript' src='js/galleryview/js/jquery.timers-1.2.js'></script>\n
	<script type='text/javascript' src='js/galleryview/js/jquery.easing.1.3.js'></script>\n\n
	<script type='text/javascript' src='js/galleryview/js/jquery.galleryview-3.0-dev.js'></script>\n
						
	<script type='text/javascript'>
		var overAllWidth = returnWidthOfPage() - 50;
		var overAllHeight = overAllWidth * .35;
		var filmStripWidth = overAllWidth / 5;
		var filmStripHeight = overAllHeight / 5;
		$(document).ready(function(){
			$('#myGallery').galleryView({
				show_panel_nav: false,
				enable_overlays: false,
				panel_animation: 'crossfade',
				panel_scale: 'fit',
				autoplay: true,
				show_infobar: false,
				transition_speed: 1200,
				transition_interval:  5000,
				easing: 'swing',
				panel_width: overAllWidth,
				panel_height: overAllHeight,
				frame_width: filmStripWidth,
				frame_height: filmStripHeight,
				filmstrip_size: 6,
				frame_opacity: 0.5,
				show_filmstrip_nav: false,
				frame_gap: 5,
				filmstrip_position: 'bottom',
			});
		});
	</script>

	<script type='text/javascript' src='./js/slideCard.js'></script>".$slideIn;
	
function makeViewsRight($result, $num_rows, $table) 
{
	for ($i=0; $i<$num_rows; $i++) {   	
		$date=mysql_result($result,$i,"date");
		$php_time = strtotime($date);
		$xml_date = date("D, M jS, Y", $php_time);
		$id=mysql_result($result,$i,"id");
		$book=mysql_result($result,$i,"book");
		$verse=mysql_result($result,$i,"verse");
		$title=mysql_result($result,$i,"title");
		if (mysql_result($result,$i,"file")){
			$audio="http://www.southhillcalvary.org".mysql_result($result,$i,"file");
		} else $audio = NULL;
		if (mysql_result($result,$i,"mfile_video")) {
		   	$video = mysql_result($result,$i,"mfile_video");
		} else $video = NULL;
		$name = add_title(mysql_result($result,$i,"name"));
		$ref = mysql_result($result,$i,"book")." ".mysql_result($result,$i,"verse"); 
		$audioElement = "<audio style='width:%s' controls='none'><source src='".$audio."' type='audio/mpeg'>Sorry your device doesn't support HTML5 audio...</audio>";
		$videoElement = "<div style='margin-top:10px; margin-left:-5px; height:225px;' id='videoHolder'>%s</div>";
		if (mysql_result($result,$i,"referencedMedia")) $referencedMedia = "<h4 style='text-align:left;'>Referenced Media...</h4><p style='margin-top:-20px; text-align:left; width:%s;'>".mysql_result($result,$i,"referencedMedia")."</p>"; 
		else $referencedMedia = NULL;
		$apology = "<p id='hidden'>".$name."<br>".$ref."<br>On: ".$xml_date."<br><br>Sorry, there is no audio or video for this study yet!</p>";
		
		if(userIsTab()){
				
			if ($audio && $video){
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'>", "100%");
				printf("<tr><td><h4>Video...</h4></td>");
				printf("<td style='text-align:right;'><p style='margin-right:25px;' onclick='slide(\"".$id."\",\"TRUE\", \"TRUE\")'>[BACK]</p></td></tr></table>");
				printf($videoElement."</div>", $video);
			} else if ($audio){ 
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'>", "100%");
				printf("<tr><td><h4>".$title."</h4></td>");
				printf("<td><p onclick='slide(\"".$id."\",\"TRUE\", \"FALSE\")'>[BACK]</p></td></tr></table>");
				printf("<p id='hidden'>".$name."<br>".$ref."<br>On: ".$xml_date."</p>".$audioElement."<br>".$referencedMedia."</div>", "98%", "98%");
			} else if ($video){ 
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'>", "100%");
				printf("<tr><td><h4>".$title."</h4></td>");
				printf("<td style='text-align:right;'><p style='margin-right:25px;' onclick='slide(\"".$id."\",\"TRUE\", \"FALSE\")'>[BACK]</p></td></tr></table>");
				printf("<p id='hidden'>".$name."<br>".$ref."<br>On: ".$xml_date."</p>");
				printf($videoElement."<br>".$referencedMedia."</div>", $video, "98%");
			} else {
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<h4>".$title."</h4>".$apology);
				printf("<p onclick='slide(\"".$id."\",\"TRUE\", \"FALSE\")'>[BACK]</p></div>");
			}
		} else {
			if ($audio && $video){
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'><tr><td><h4>".$title."</h4></td>", "100%");
				printf("<td style='vertical-align:top;'><p onclick='slidePhone(\"".$id."\",\"TRUE\", \"TRUE\")'>[BACK]</p></td></tr></table>");
				printf("<p style='text-align:left; margin-top:-15px;'>".$name."<br>".$ref."<br>On: ".$xml_date."</p>".$videoElement."<br><br>".$audioElement."<br>".$referencedMedia."</div>", $video, "98%", "98%");
			} else if ($audio){	
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'><tr><td><h4>".$title."</h4></td>", "100%");
				printf("<td style='vertical-align:top;'><p onclick='slidePhone(\"".$id."\",\"TRUE\", \"FALSE\")'>[BACK]</p></td></tr></table>");
				printf("<p style='text-align:left; margin-top:-15px;'>".$name."<br>".$ref."<br>On: ".$xml_date."</p>");
				printf($audioElement."<br>".$referencedMedia."</div>", "98%", "98%");
			} else if ($video){ 	
				printf("<div class='hidden' id='sermon".$id."'>");
				printf("<table style='width:%s;'><tr><td><h4>".$title."</h4></td>", "100%");
				printf("<td style='vertical-align:top;'><p onclick='slidePhone(\"".$id."\",\"TRUE\", \"TRUE\")'>[BACK]</p></td></tr></table>");
				printf("<p style='text-align:left; margin-top:-15px;'>".$name."<br>".$ref."<br>On: ".$xml_date."</p>");
				printf($videoElement."<br>".$referencedMedia."</div>", $video, "98%");
			} else {	
				printf("<div class='hidden' id='sermon".$id."'>".$apology."<p onclick='slidePhone(\"".$id."\",\"TRUE\", \"FALSE\")'>[BACK]</p></div>");
			}
		}
		}
}

function makeViewsLeft($result, $num_rows, $table) 
{
	for ($i=0; $i<$num_rows; $i++) {	    
	    $date=mysql_result($result,$i,"date");
	    $php_time = strtotime($date);
	    $xml_date = date("D, M jS, Y", $php_time);
	    $id=mysql_result($result,$i,"id");
	    $book=mysql_result($result,$i,"book");
	    $verse=mysql_result($result,$i,"verse");
	    $title=mysql_result($result,$i,"title");
	    if (mysql_result($result,$i,"file")) $audio="http://www.southhillcalvary.org".mysql_result($result,$i,"file");
		else $audio = NULL;
	    if (mysql_result($result,$i,"mfile_video")) $video = mysql_result($result,$i,"mfile_video");
	    else $video = NULL;
	    $name = add_title(mysql_result($result,$i,"name"));
	    $ref = mysql_result($result,$i,"book")." ".mysql_result($result,$i,"verse"); 
	    $audioElement = "<audio style='width:%s' controls='none'><source src='".$audio."' type='audio/mpeg'>Sorry your device doesn't support HTML5 audio...</audio>";
		if (mysql_result($result,$i,"referencedMedia")) $referencedMedia = "<h4>Referenced Media...</h4><p style='margin-top:-20px; width:%s;'>".mysql_result($result,$i,"referencedMedia")."</p>";
		else $referencedMedia = NULL;
		if ($video && $audio){
			printf("<div class='hidden' id='leftSermon".$id."'>");
			printf("<h4 style='margin-top:5px;'>".$title."</h4>");
			printf("<p>".$name."<br>".$ref."<br>On: ".$xml_date."</p>".$audioElement."<br>".$referencedMedia."</div>", "98%", "98%");
		}
	}
}

function mgalleryview_elements($image, $date, $title) 
{
	printf("\t\t<li>\n");	
	$t = htmlspecialchars($title);
	printf("\t\t\t<img id='currImg' src='http://www.southhillcalvary.org%s' alt='%s' title='%s' >\n", $image, $t, $t);
	printf("\t\t\t</img>\n");
	printf("\t\t</li>\n");
}

function mstay_connected($image, $link, $title, $tagline) 
{	
	printf("\t\t\t<div class='blocks'>\n");	
	printf("\t\t\t\t<div class='connected1'>\n");
	printf("\t\t\t\t\t<a href='%s' target='_blank'><img src='%s' alt='%s'/></a>\n", $link, $image, $title);
	printf("\t\t\t\t</div>\n");
	printf("\t\t\t\t<div class='connectedText'>\n");
	printf("\t\t\t\t\t<a class='title' href='%s' target='_blank'><h5>%s</h5></a>\n", $link, $title, $link, $tagline);
	printf("\t\t\t\t</div>\n");
	printf("\t\t\t</div>\n");	
}

function msermon_snippet ($result, $num_rows,$table) 
{
	for ($i=0; $i<$num_rows; $i++) {   
		$date=mysql_result($result,$i,"date");
		$php_time = strtotime($date);
		$xml_date = date("D, M jS, Y", $php_time);
		$id=mysql_result($result,$i,"id");
		$book=mysql_result($result,$i,"book");
		$verse=mysql_result($result,$i,"verse");
		$title=mysql_result($result,$i,"title");
		if (mysql_result($result,$i,"file")){
			$audio="http://www.southhillcalvary.org".mysql_result($result,$i,"file");
		} else $audio = NULL;
		if (mysql_result($result,$i,"mfile_video")) {
		   	$video = mysql_result($result,$i,"mfile_video");
		} else $video = NULL;
		$name = add_title(mysql_result($result,$i,"name"));
		$ref = mysql_result($result,$i,"book")." ".mysql_result($result,$i,"verse"); 
		$ref=$book." ".$verse;
	    if ($video && $audio) $two = "TRUE";
	    else $two = "FALSE";
	    if (userIsTab()){
			printf("<div onclick='slide(\"%s\",\"FALSE\",\"%s\")' id='blocks' class='blocks'>\n", $id, $two);
			if (strlen($title) >= 50){
				$title = substr($title, 0, 47)."...";
			}
		} else {
			printf("<div onclick='slidePhone(\"%s\",\"FALSE\", \"%s\")' id='blocks' class='blocks'>\n", $id, $two);
			if (strlen($title) >= 35){
				$title = substr($title, 0, 32)."...";
			}	
		}
		printf("<h6 id='sermonSnippetTitle'>%s</h6>\n", $title);
		printf("<p id='subText'>%s on %s</p>\n", $ref, $xml_date);
		printf("</div>\n");
	}

}

startPageNoPageContent($title, $meta_key, $meta_desc, $morehtml, $morejava);

$table = "events";
connect_select_test($table);
$query="SELECT * FROM `events` WHERE `homepage`='1' && `start` >= '".date("Y-m-d")."' ORDER BY `start` ASC LIMIT 0,4";
$result=mysql_query($query) or die (mysql_error());
$num_rows=mysql_num_rows($result);
printf("<div class='clear'>&nbsp;</div>\n");
printf("<div class='galHolder' id='plainlist' onclick='refreshPage(\"/events.php\")'>\n");
printf("\t<ul id='myGallery'>\n");
$now = time();
$i=0;
while ($i < $num_rows) {
	$date=mysql_result($result,$i,"start");
	$no_start=mysql_result($result,$i,"no_start");
	$php_start_time = strtotime($date);
	$date=mysql_result($result,$i,"end");
	$no_end=mysql_result($result,$i,"no_end");
	$php_end_time = strtotime($date);
	$php_end_day = date("z", $php_end_time);
	$php_start_day = date("z",$php_start_time);
	if ($now > $php_end_time) {
		$i++;
		continue;
	}
	if ($no_start) {
		$duration = 0;
	} else if ($no_end) {
		$date1 = date("l, F jS, g:i a", $php_start_time);
		$duration = $date1;
	} else if ($php_end_day != $php_start_day) {
		$date1 = date("l, F jS, g:i a", $php_start_time);
		$date2 = date("l, F jS", $php_end_time);
		$duration = $date1 . " - " . $date2;
	} else {
		$date1 = date("l, F jS, g:i a", $php_start_time);
		$date2 = date("g:i a", $php_end_time);
		$duration = $date1 . " - " . $date2;
	}
	$duration = strtoupper($duration);
	$title=strtoupper(mysql_result($result,$i,"title"));
	$announcement=mysql_result($result,$i,"announcement");
	$ministry=mysql_result($result,$i,"ministry");
	$flyer=mysql_result($result,$i,"flyer");
	$directions=mysql_result($result,$i,"directions");
	$id=mysql_result($result,$i,"id");
	$picture=mysql_result($result,$i,"picture");
	$link='./event_details.php?id='.$id;
	mgalleryview_elements($picture, $duration, $title);
	$i++; 
}
printf("\t</ul>\n");
printf("</div><br>\n");
mysql_close();
$table = "sermons";
connect_select_test($table);
$query="SELECT * FROM $table WHERE `service`='Sunday' || `service`='Wednesday' ORDER BY date DESC";
$result=mysql_query($query) or die (mysql_error());	
if (userIsTab()){
	printf("<div id='col'>\n");
	printf("\t<ul>\n");
	printf("\t\t<li id='stayConnectedBlock'>\n");
	makeViewsLeft($result,3, $table);
	printf("<div id='stayConnected'>\n");
	printf("\t\t\t<h3 style='Text-align:left; margin-left: 10px; margin-top: 20px; font-family: Gnuolane;'>Stay Connected</h3>\n");
	
	$image = "http://www.southhillcalvary.org/images/wp_35x35.png";
	$link = 'http://blog.southhillcalvary.org';
	$title = 'Redeeming the Times';
	$tagline = 'Read our church blog.';
	mstay_connected($image, $link, $title, $tagline);
	
	$image = 'http://www.southhillcalvary.org/images/wp_35x35.png';
	$link = 'http://pastorronsanchez.com/';
	$title = 'Pastor Ron&#39;s Blog';
	$tagline = 'Read Pastor Ron&#39;s thoughts on life.';
	mstay_connected($image, $link, $title, $tagline);
	
	$image = 'http://www.southhillcalvary.org/images/facebook_35x35.png';
	$link = 'http://www.facebook.com/southhillcalvary';
	$title = 'Facebook';
	$tagline = 'Visit us on Facebook.';
	mstay_connected($image, $link, $title, $tagline);
	
	$image = 'http://www.southhillcalvary.org/images/vimeo_35x35.png';
	$link = 'http://www.vimeo.com/southhillcalvary';
	$title = 'Vimeo';
	$tagline = 'View an assortment of videos.';
	mstay_connected($image, $link, $title, $tagline);
	
	printf("\t\t</div></li>\n");
	printf("\t\t<li id='sermons'>\n");
	printf("<div id='recents'><h3 style='Text-align:left; margin-left: 10px; margin-top: 20px; font-family: Gnuolane;'>Recent Messages</h3>\n");
	msermon_snippet($result,3,$table);
	printf("<div class='blocks'><a href='./sermon.php'><h5 id='sermonSnippetTitle' style='margin-top: 5px;'>Visit All Archived Messages</h5></a></div></div>\n");
	makeViewsRight($result,3, $table);
	mysql_close();
	printf("\t\t</li>\n");
	printf("\t</ul>\n");
	printf("</div>\n");	
	printf("</br></br></br></br>\n");
} else {
	printf("<div id='col'>\n");
	printf("\t<ul>\n");	
	printf("\t\t<li id='sermons'>\n");
	printf("<div id='recents'>");
	printf("\t\t\t<h4 style='text-align:center; font-family: Gnuolane; margin: -1px 0px 0px 0px;'>Most Recent Teaching</h4>\n");
	msermon_snippet($result,1,$table);
	printf("</div>\n");
	makeViewsRight($result,1, $table);
	printf("\t\t</li>\n");
}
endPageNoContent();
?>